package com.hospital.data.simulation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.common.pojo.TDepartment;
import com.hospital.data.simulation.exception.DepartmentServiceException;
import com.hospital.data.simulation.exception.enums.DepartmentServiceExpCode;
import com.hospital.data.simulation.mapper.TDepartmentMapper;
import com.hospital.data.simulation.service.TDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TDepartmentServiceImpl extends ServiceImpl<TDepartmentMapper, TDepartment> implements TDepartmentService{
    @Autowired
    private TDepartmentMapper tDepartmentMapper;
    @Override
    public Long addDepartment(TDepartment department) {
        if(tDepartmentMapper.insert(department)==0){
            throw new DepartmentServiceException(DepartmentServiceExpCode.ADD_DEPARTMENT_FAILED);
        }
        return department.getId();
    }

    @Override
    public void deleteDepartment(Integer id) {
        if(tDepartmentMapper.deleteById(id)==0){
            throw new DepartmentServiceException(DepartmentServiceExpCode.DELETE_DEPARTMENT_FAILED);
        }
    }

    @Override
    public void updateDepartment(TDepartment department) {
        if(tDepartmentMapper.updateById(department)==0){
            throw new DepartmentServiceException(DepartmentServiceExpCode.UPDATE_DEPARTMENT_FAILED);
        }
    }
}
